package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.SparePartBackDao;
import com.sugon.entity.SparePartBackEntity;
import com.sugon.service.SparePartBackService;
import com.sugon.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static com.sugon.utils.ShiroUtils.getUserId;

/**
 * 退库记录Service实现类
 *
 * @author sugon
 * @date 2019-07-19 16:08:15
 */
@Service("sparePartBackService")
public class SparePartBackServiceImpl implements SparePartBackService {

    @Autowired
    private SparePartBackDao sparePartBackDao;

    @Override
    public SparePartBackEntity queryObject(String id) {
        return sparePartBackDao.queryObject(id);
    }

    @Override
    public List<SparePartBackEntity> queryList(Map<String, Object> map) {
        return sparePartBackDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return sparePartBackDao.queryTotal(map);
    }

    @Override
    public int save(SparePartBackEntity sparePartBack) {
        sparePartBack.setId(RandomUtil.randomString(32));
        sparePartBack.setCreateUser(getUserId());
        sparePartBack.setCreateDate(DateUtil.date());
        sparePartBack.setDelFlag(Integer.valueOf(Constant.IS_NOT_DEL));
        return sparePartBackDao.save(sparePartBack);
    }

    @Override
    public int statTotalNum(String posId, String month) {
        Integer totalNum = sparePartBackDao.statTotalNum(posId, month);
        return totalNum == null ? 0 : totalNum;
    }

    @Override
    public int update(SparePartBackEntity sparePartBack) {
        return sparePartBackDao.update(sparePartBack);
    }

    @Override
    public int delete(String id) {
        return sparePartBackDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return sparePartBackDao.deleteBatch(ids);
    }
}
